<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="css/bootstrap/3.3.6/bootstrap.css">
    <link rel="stylesheet" href="css/fore/login.css">
    <script>
        $(function(){
            $("#login").click(function(){
                var data = $("#formLogin").serialize();
                console.log(data);
                $.post(
                    "fore_login",
                    data,
                    function(result){
                        console.log(result);
                        var obj = jQuery.parseJSON(result);
                        console.log(obj.flag);
                        switch (parseInt(obj.flag)) {
                            case -1: alert("用户名、密码或用户类型错误"); break;
                            case 0: window.location.replace("admin/listCoach.html"); break;
                            case 1: window.location.replace("admin/coach_admin.html"); break;
                            case 2: window.location.replace("index.html"); break;
                        }
                    }
                );
            });
        });

    </script>
</head>
<body onload="pre()">
    <div class="main">
        <p id="main-p">驾校练车网上平台咨询管理</p>

        <form id="formLogin" action="fore_login" method="post">

            <input type="text" onkeyup="tan()" id="kuang" class="form-control main-text" placeholder="请输入用户名" name="username" required>
            <p id="login-warning">请输入用户名</p>
            <input type="password" onkeyup="tan()" id="pw-kuang" class="form-control main-text" placeholder="请输入密码" name="password" required>
            <p id="pw-warning">请输入密码</p>
            <div class="radio main-radio">
                <div class="main-r-r fl">
                    <input type="radio" class="main-radio-r"  value="0" style="margin-left: 20px" name="type">
                    <span>管理员</span>
                </div>
                <div class="main-r-r fl">
                    <input type="radio" class="main-radio-r" value="1" style="margin-left: 20px" name="type">
                    <span>教练</span>
                </div>
                <div class="main-r-r fl">
                    <input type="radio" class="main-radio-r" value="2" style="margin-left: 20px" name="type" checked="checked">
                    <span>学员</span>
                </div>
            </div>
            <div class="main-btn">
                <button id="login" type=button class="btn btn-success fl">登陆</button>
                <button type="button" class="btn btn-danger fl main-btn-2">
                    <a style="color:#fff;text-decoration:none;" href="register.html">注册</a>
                </button>
            </div>
        </form>
    </div>
    <script>
        function tan() {
            var a = document.getElementById('kuang').value;
            var ab = document.getElementById('kuang');

            console.log(a);
            var b=  document.getElementById('login-warning');
            if(a==""){
                ab.style.border=2+'px solid red';
                b.style.display='block';
            }else{

                ab.style.border= 2 +'px solid white';
                b.style.display='none';
            }

            var c = document.getElementById('pw-kuang').value;
            var cd = document.getElementById('pw-kuang');

            console.log(c);
            var d=  document.getElementById('pw-warning');
            if(c==""){
                cd.style.border=2+'px solid red';
                d.style.display='block';
            }else{

                cd.style.border= 2 +'px solid white';
                d.style.display='none';
            }
        }
        function GetQueryString(name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)
                return  unescape(r[2]);
            return null;
        }
        function pre(){
            let msg = GetQueryString("msg");
            if(msg != null && msg == -1){
                alert("请先登陆")
            }

        }
    </script>
</body>
</html>